package caidan;

import java.awt.Font;
import java.awt.Insets;
import java.awt.geom.RoundRectangle2D;

import javax.swing.border.Border;

import jinyilw.swing.FontTools;
import jinyilw.swing.graphics.GraphicsTools;
import jinyilw.swing.rlaf.utils.RBorderFactory;
import jinyilw.swing.visuals.panel.PositionProducer;

public class PositionConfiger extends PositionProducer
{
	static final Border border = RBorderFactory.getDefaultBorder();
	static final Insets insets = border.getBorderInsets(null);
	final RoundRectangle2D.Float roundShape = new RoundRectangle2D.Float();
	Font textFont;
	int height, textHeight;

	public PositionConfiger()
	{
	}

	public PositionConfiger(int maxCol)
	{
		super(maxCol);
	}

	@Override
	public void updatePramater(int ww, int hh, int ss, int up, int left)
	{
		roundShape.setRoundRect(insets.left - 2, insets.top - 2,
				ww - insets.left - insets.right + 4,
				hh - insets.top - insets.bottom + 4, 8, 8);
		float size = Math.min(12f * ww / 90, 22);
		textFont = FontTools.getSystemFont((int) size);
		textHeight = GraphicsTools.getFontMetrics(textFont).getHeight();
		textHeight += insets.bottom;
		height = textHeight - 1;
		super.updatePramater(ww, hh, ss, up, left);
	}

	@Override
	public void updatePramater(int ww, int hh, int ss)
	{
		roundShape.setRoundRect(insets.left - 2, insets.top - 2,
				ww - insets.left - insets.right + 4,
				hh - insets.top - insets.bottom + 4, 8, 8);
		float size = Math.min(12f * ww / 90, 22);
		textFont = FontTools.getSystemFont(Math.round(size));
		// System.out.println(textFont);
		textHeight = GraphicsTools.getFontMetrics(textFont).getHeight();
		textHeight += insets.bottom;
		height = textHeight - 1;
		super.updatePramater(ww, hh, ss);
	}

	@Override
	public void setPramater(int ww, int hh, int ss)
	{
		super.setPramater(ww, hh, ss);
		roundShape.setRoundRect(insets.left - 2, insets.top - 2,
				ww - insets.left - insets.right + 4,
				hh - insets.top - insets.bottom + 4, 8, 8);
		float size = Math.min(12f * ww / 90, 22);
		textFont = FontTools.getSystemFont((int) size);
		// System.out.println(textFont);
		textHeight = GraphicsTools.getFontMetrics(textFont).getHeight();
		textHeight += insets.bottom;
		height = textHeight - 1;
	}

}
